﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MySql.Data.MySqlClient;
using seo.Data;

namespace seo.DAO
{
    public class DbInfoDao
    {
        private MySqlConnection conn;

        public DbInfoDao(MySqlConnection conn)
        {
            this.conn = conn;
        }

        public DbInfo getDbInfoByDomain(string domain)
        {

            List<DbInfo> list = new List<DbInfo>();

            MySqlCommand command = conn.CreateCommand();
            MySqlDataReader reader;

            command.CommandText = "select iddb_info,ipaddress,portnumber,databasename,username,password,prefix,domainname from db_info where domainname = '" + domain + "' and deleteflg='0'";

            reader = command.ExecuteReader();

            while (reader.Read())
            {
                DbInfo dbinfo = new DbInfo();

                dbinfo.iddb_info = reader.GetInt32(0);
                dbinfo.ipaddress = reader.GetString(1);
                dbinfo.portnumber = reader.GetString(2);
                dbinfo.databasename = reader.GetString(3);
                dbinfo.username = reader.GetString(4);
                dbinfo.password = reader.GetString(5);
                dbinfo.prefix = reader.GetString(6);
                dbinfo.domainname = reader.GetString(7);

                list.Add(dbinfo);
            }

            if (list.Count > 0)
            {
                return list[0];
            }
            else {
                return null;
            }
        }
    }
}
